﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Data;

namespace LS.DicomViewer.Converters
{
    /// <summary>
    /// 能枚举到的值时，返回给定的值
    /// </summary>
    public class IncludeToValueConverter : IValueConverter
    {
        /// <summary>
        /// 当TrueEnums中包含给定枚举值时返回的值
        /// </summary>
        public object TrueValue { get; set; }
        /// <summary>
        /// 当TrueEnums中不包含给定枚举值时返回的值
        /// </summary>
        public object FalseValue { get; set; }
        /// <summary>
        /// 为True时的枚举集合
        /// </summary>
        public IEnumerable<object> Values { get; set; }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (Values == null || Values.Count() == 0) return TrueValue;
            if (value != null && value.GetType() == Values.First().GetType())
            {
                return TrueValue;
            }
            if (Values.Contains(parameter)) return TrueValue;

            return FalseValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        public object GetValue(object parameter)
        {
            if (Values.Contains(parameter)) return TrueValue;
            return FalseValue;
        }
    }
}
